/*
 * @Title: community
 * @Description: TODO
 * @author MI
 * @date 2022/7/6 16:38
 * @version
 */
package com.shanshan.community.entity;

/**
 * @author SHANSHAN
 * @ClassName: Page
 * @Description: 封装页面信息
 * @date 2022/7/6 16:38
 */
public class Page {
    private int current = 1;//当前页
    private int limit = 10;//每页显示行数
    private int rows;//数据总数
    //查询路径
    private String path;

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        if (current >= 1) {
            this.current = current;
        }
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        if (limit > 0 && limit <= 100) {
            this.limit = limit;
        }
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    //当前页的起始行
    public int getOffset() {
        return (current - 1) * limit;
    }

    //总页数
    public int getTotal() {
        if (rows % limit == 0) {
            return rows / limit;
        } else return rows / limit + 1;
    }

    //显示的起始页
    public int getFrom() {
        int from = current - 2;
        return Math.max(from, 1);
    }

    //显示的末页
    public int getTo() {
        int to = current + 2;
        int total = getTotal();
        return Math.min(to, total);
    }
}
